package org.anyin.gitee.cloud.lib.core.web;

import lombok.Data;

@Data
public class ApiResponse<T> {

    private static final String SUCCESS_CODE = "00";
    private static final String SUCCESS_MESSAGE = "success";

    private String id;
    private String code;
    private String message;
    private T data;

    public Boolean getSuccess(){
        return SUCCESS_CODE.equals(this.code);
    }

    public static ApiResponse success(){
        ApiResponse response = new ApiResponse();
        response.code = SUCCESS_CODE;
        response.message = SUCCESS_MESSAGE;
        return response;
    }

    public static <T> ApiResponse<T> success(T data){
        ApiResponse<T> response = new ApiResponse<>();
        response.code = SUCCESS_CODE;
        response.message = SUCCESS_MESSAGE;
        response.data = data;
        return response;
    }

    public static  ApiResponse error(String code, String message){
        ApiResponse response = new ApiResponse<>();
        response.code = code;
        response.message = message;
        return response;
    }

    public static ApiResponse error(String id, String code, String message){
        ApiResponse response = new ApiResponse<>();
        response.id = id;
        response.code = code;
        response.message = message;
        return response;
    }
}
